Get all drives in MAC ?
Hi Bruce,
Maui approach is to run windows in a vm, and use visual studio for windows.
How i get in C# all the drives in MAC ?
Thanks in advance,
.NET MAUI
-
Dani_S 2,886 Reputation points
2024-05-14T03:30:52.98+00:00 and what kind of drives i have in MAC?
-
Bruce (SqlWork.com) 58,121 Reputation points
2024-05-14T15:39:45.4333333+00:00 Your question is not clear. Unix has a unified file system. Drives are mounted into file system, so you just use directory services. macOS supports both auto mounts and hard mounts.
if you programmatically want device info, then you would use IOKit sdk.
note: as Maui build catalyst apps, you have limited permissions.
-
Dani_S 2,886 Reputation points
2024-05-14T17:14:18.4466667+00:00 Can you please supply code sniped how to get programmatically the device info,
use IOKit sdk?
-
Bruce (SqlWork.com) 58,121 Reputation points
2024-05-14T21:09:53.59+00:00 what info do you want? the standard unix approach would be to spawn (fork) the ioreg or system_profiler utility and parse the output:
http://www.manpagez.com/man/8/ioreg/ https://ss64.com/mac/system_profiler.html
example - usb device info:
% ioreg -p IOUSB +-o Root <class IORegistryEntry, id 0x100000100, retain 30> +-o AppleT8103USBXHCI@00000000 <class AppleT8103USBXHCI, id 0x1000004ed, registered, matched, active, busy 0 (13 ms), retain 39> +-o AppleT8103USBXHCI@01000000 <class AppleT8103USBXHCI, id 0x10000037f, registered, matched, active, busy 0 (2 ms), retain 39> +-o AppleUSBXHCITR@02000000 <class AppleUSBXHCITR, id 0x1000a7757, registered, matched, active, busy 0 (1226 ms), retain 375> +-o USB2 Hub@02100000 <class IOUSBHostDevice, id 0x1000a7762, registered, matched, active, busy 0 (1215 ms), retain 36> | +-o Studio Display@02140000 <class IOUSBHostDevice, id 0x1000a777f, registered, matched, active, busy 0 (882 ms), retain 159> | +-o USB Flash Disk @02130000 <class IOUSBHostDevice, id 0x1000dc51b, registered, matched, active, busy 0 (118 ms), retain 29> +-o USB3 Gen2 Hub@02300000 <class IOUSBHostDevice, id 0x1000a7771, registered, matched, active, busy 0 (256 ms), retain 33> +-o INIC-3609 @02310000 <class IOUSBHostDevice, id 0x1000a778c, registered, matched, active, busy 0 (251 ms), retain 45>
example - list USB device name only:
% ioreg -p IOUSB -w0 | sed 's/[^o]*o //; s/@.*$//' | grep -v '^Root.*' AppleT8103USBXHCI AppleT8103USBXHCI AppleUSBXHCITR USB2 Hub Studio Display USB Flash Disk USB3 Gen2 Hub INIC-3609
example usb profile in json:
% system_profiler SPUSBDataType -json { "SPUSBDataType" : [ { "_name" : "USB31Bus", "host_controller" : "AppleT8103USBXHCI" }, { "_name" : "USB31Bus", "host_controller" : "AppleT8103USBXHCI" }, { "_items" : [ { "_items" : [ { "_name" : "INIC-3609 ", "bcd_device" : "1.40", "bus_power" : "900", "bus_power_used" : "144", "device_speed" : "super_speed", "extra_current_used" : "0", "location_id" : "0x02310000 / 4", "manufacturer" : "Initio ", "product_id" : "0x3940", "serial_num" : "************", "vendor_id" : "0x13fd (Initio Corporation)" } ], "_name" : "USB3 Gen2 Hub", "bcd_device" : "52.12", "bus_power" : "900", "bus_power_used" : "0", "device_speed" : "super_speed_plus", "extra_current_used" : "0", "location_id" : "0x02300000 / 2", "manufacturer" : "Apple", "product_id" : "0x101e", "serial_num" : "***********", "vendor_id" : "apple_vendor_id" }, { "_items" : [ { "_name" : "USB Flash Disk ", "bcd_device" : "1.00", "bus_power" : "500", "bus_power_used" : "500", "device_speed" : "high_speed", "extra_current_used" : "0", "location_id" : "0x02130000 / 7", "manufacturer" : "General ", "Media" : [ { "_name" : "USB Flash Disk", "bsd_name" : "disk16", "Logical Unit" : 0, "partition_map_type" : "master_boot_record_partition_map_type", "removable_media" : "yes", "size" : "252.7 MB", "size_in_bytes" : 252706816, "smart_status" : "Verified", "USB Interface" : 0, "volumes" : [ { "_name" : "NO NAME", "bsd_name" : "disk16s1", "file_system" : "MS-DOS FAT16", "free_space" : "184.6 MB", "free_space_in_bytes" : 184586240, "iocontent" : "DOS_FAT_16", "mount_point" : "/Volumes/NO NAME", "size" : "252.7 MB", "size_in_bytes" : 252690432, "volume_uuid" : "5190990C-0600-352D-8410-858A283489CE", "writable" : "yes" } ] } ], "product_id" : "0x800b", "serial_num" : "*****", "vendor_id" : "0x8644" }, { "_name" : "Studio Display", "bcd_device" : "2.01", "bus_power" : "500", "bus_power_used" : "500", "device_speed" : "high_speed", "extra_current_used" : "0", "location_id" : "0x02140000 / 3", "manufacturer" : "Apple Inc.", "product_id" : "0x1114", "serial_num" : "*********************", "vendor_id" : "apple_vendor_id" } ], "_name" : "USB2 Hub", "bcd_device" : "52.12", "bus_power" : "500", "bus_power_used" : "0", "device_speed" : "high_speed", "extra_current_used" : "0", "location_id" : "0x02100000 / 1", "manufacturer" : "Apple", "product_id" : "0x101d", "serial_num" : "************", "vendor_id" : "apple_vendor_id" } ], "_name" : "USB31Bus", "host_controller" : "AppleUSBXHCITR", "pci_device" : "0x15f0 ", "pci_revision" : "0x0006 ", "pci_vendor" : "0x8086 " } ] }
-
Dani_S 2,886 Reputation points
2024-05-23T06:12:23.9033333+00:00 Hi,
There is no code in C# to get all the drives and volumes?
In windows i did :
DriveInfo[] drives = DriveInfo.GetDrives();
-
Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 27,126 Reputation points • Microsoft Vendor
2024-05-24T06:11:19.4733333+00:00 About IOKit, you can see IOKit | Apple Developer Documentation
-
Dani_S 2,886 Reputation points
2024-05-24T10:39:08.3766667+00:00 can you please a sniped code?
-
Dani_S 2,886 Reputation points
2024-05-24T10:39:28.55+00:00 In csharp?
-
Bruce (SqlWork.com) 58,121 Reputation points
2024-05-25T04:28:51.0566667+00:00 Here is GitHub library with samples. Not sure it’s maintained.
https://github.com/CartBlanche/IOKit-Sharp?tab=readme-ov-file
-
Dani_S 2,886 Reputation points
2024-05-26T17:50:10.5633333+00:00 Can you please give a code how to do that ?
-
Bruce (SqlWork.com) 58,121 Reputation points
2024-05-27T22:20:51.6466667+00:00 code to do what? what kind of information are you looking for? what kind of devices and volumes? also do you understand what drives and volumes are on unix system? a volume can be a mountable file, like most installers.
unix also supports automount. that is the first reference to the directory mount point causes the filesystem (local device or network) to mount.
if you explained the problem you are trying to solve, and the Maui platform, IOS, MacCatalyst, etc, we could give better help. In general unix hides the implementation of devices and volumes. They are mounted into the directory structure, and accessed via the file system.
note: IOKit is written in a restricted subset of C++. It is the base library for writing device drivers. It should be easily callable via p-invoke from c#, though I would not try to write a driver in c#.
Sign in to comment